﻿using System.Collections.Generic;
using System.IO;
using Volo.Abp.Content;
using Volo.Abp.DependencyInjection;

namespace Thinker.SignChannel.Excels;

public class LocalizedExcelAccessor(ExcelAccessor excelAccessor, LocalizationTranslator translator)
    : ITransientDependency
{
    public IRemoteStreamContent CreateStream<T>(IEnumerable<T> items, string name,
        string? filename = null)
    {
        filename ??= $"{name}.xlsx";
        var memoryStream = new MemoryStream();
        excelAccessor.WriteListToExcel(items, memoryStream, translator, name);
        return RemoteContentCreator.CreateExcel(memoryStream, filename);
    }

    public IEnumerable<T> ReadListFromExcel<T>(Stream stream) where T : new()
    {
        return excelAccessor.ReadListFromExcel<T>(stream, translator);
    }
}